package top.hcode.hoj.service.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nutz.lang.Strings;
import org.springframework.stereotype.Component;
import top.hcode.hoj.dao.org.SchoolHasUserDao;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.org.SchoolHasUser;

/**
 * @author orangej
 * @since 2025-01-21
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AdminSchoolHasUserService {
    private final SchoolHasUserDao schoolHasUserDao;

    public IPage<SchoolHasUser> getSchoolHasUserList(QuerySampleDTO querySampleDTO) {
        IPage<SchoolHasUser> pager = new Page<>(querySampleDTO.getCurrentPage(), querySampleDTO.getLimit());

        QueryWrapper<SchoolHasUser> query = new QueryWrapper<>();
        if (Strings.isNotBlank(querySampleDTO.getKeyword())) {
            query.like("title", querySampleDTO.getKeyword());
        }
        schoolHasUserDao.page(pager, query);
        return pager;
    }

    public SchoolHasUser getSchoolHasUser(Long id) {
        return schoolHasUserDao.getById(id);
    }

    public SchoolHasUser saveSchoolHasUser(SchoolHasUser schoolHasUser) {
        schoolHasUserDao.saveOrUpdate(schoolHasUser);
        return schoolHasUser;
    }

    public void deleteSchoolHasUser(Long id) {
        schoolHasUserDao.removeById(id);
    }
}
